package cn.hnu.data;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

 class StationData {
//    private int stationid;
//    private int facilitytype;
//    private String location;
//
//    public StationData(int stationid, int facilitytype, String location) {
//        this.stationid = stationid;
//        this.facilitytype = facilitytype;
//        this.location = location;
//    }
//
//    public int getStationid() {
//        return stationid;
//    }
//
//    public void setStationid(int stationid) {
//        this.stationid = stationid;
//    }
//
//    public int getFacilitytype() {
//        return facilitytype;
//    }
//
//    public void setFacilitytype(int facilitytype) {
//        this.facilitytype = facilitytype;
//    }
//
//    public String getLocation() {
//        return location;
//    }
//
//    public void setLocation(String location) {
//        this.location = location;
//    }
//
//    @Override
//    public String toString() {
//        return "StationData{" +
//                "stationid=" + stationid +
//                ", facilitytype=" + facilitytype +
//                ", location='" + location + '\'' +
//                '}';
//    }
//
//    //生成充电桩的数据  参数：充电桩的个数
//    public static ArrayList<StationData> generateStations(int num) {
//        Random random = new Random();
//        List<String> locations = Arrays.asList("江岸区", "江汉区", "硚口区", "汉阳区", "武昌区", "青山区", "洪山区", "东西湖区", "汉南区", "蔡甸区",
//                "江夏区", "黄陂区", "新洲区");
//        //"stationid", "facilitytype", "location"
//        ArrayList<StationData> stationDatas = new ArrayList<>();
//        for (int i = 0; i < num; i++) {
//            //随机抽取一个充电桩的区域
//            int j = random.nextInt(locations.size());
//            //System.out.println(locations.get(j));
//            //随机生成充电桩的类型
//            int k = random.nextInt(3) + 1;
//            stationDatas.add(new StationData(i+1,k,locations.get(j)));
//        }
//        return stationDatas;
//    }
//
//    //将充电桩数据保存为 CSV 文件
//    public static void saveLocationsToCSV(List<StationData> sds, String fileName) throws IOException {
//        FileWriter fw = new FileWriter(fileName);
//        // 写入 CSV 表头
//        //fw.write("uid,username,uage,regtime\n");
//        // 逐行写入充电桩数据
//        for (StationData sd : sds) {
//            fw.write(sd.getStationid() + "," + sd.getFacilitytype()+","+sd.getLocation() + "\n");
//        }
//        fw.close();
//        System.out.println("充电桩数据已保存到 " + fileName);
//    }
//    //main方法
//    public static void main(String[] args) throws IOException {
//        saveLocationsToCSV(generateStations(2000),"data/stations_dataset.csv");
//    }
//}
private int stationid;
     private int facilitytype;
     private String location;
     private double consumptionAmount; // 新增消费金额属性

     // 修改构造函数以包含消费金额参数
     public StationData(int stationid, int facilitytype, String location, double consumptionAmount) {
         this.stationid = stationid;
         this.facilitytype = facilitytype;
         this.location = location;
         this.consumptionAmount = consumptionAmount; // 初始化消费金额
     }

     public int getStationid() {
         return stationid;
     }

     public int getFacilitytype() {
         return facilitytype;
     }

     public String getLocation() {
         return location;
     }

     public double getConsumptionAmount() { // 新增getter方法
         return consumptionAmount;
     }

     @Override
     public String toString() {
         return "StationData{" +
                 "stationid=" + stationid +
                 ", facilitytype=" + facilitytype +
                 ", location='" + location + '\'' +
                 ", consumptionAmount=" + consumptionAmount + // 显示消费金额
                 '}';
     }

     // 生成充电桩的数据，参数：充电桩的个数
     public static ArrayList<StationData> generateStations(int num) {
         Random random = new Random();
         List<String> locations = Arrays.asList("江岸区", "江汉区", "硚口区", "汉阳区", "武昌区", "青山区", "洪山区", "东西湖区", "汉南区", "蔡甸区",
                 "江夏区", "黄陂区", "新洲区");

         ArrayList<StationData> stationDatas = new ArrayList<>();
         for (int i = 0; i < num; i++) {
             // 随机抽取一个充电桩的区域
             int j = random.nextInt(locations.size());
             // 随机生成充电桩的类型
             int k = random.nextInt(3) + 1;
             // 随机生成消费金额（范围0到100）
             double consumptionAmount = Math.round(random.nextDouble() * 1000 * 100.0) / 100.0; // 保留两位小数
             stationDatas.add(new StationData(i + 1, k, locations.get(j), consumptionAmount)); // 新增消费金额
         }
         return stationDatas;
     }

     // 将充电桩数据保存为 CSV 文件
     public static void saveLocationsToCSV(List<StationData> sds, String fileName) throws IOException {
         FileWriter fw = new FileWriter(fileName);
         // 写入 CSV 表头
         fw.write("sessionId,facilitytype,location,consumptionAmount\n");

         // 逐行写入充电桩数据
         for (StationData sd : sds) {
             fw.write(sd.getStationid() + "," +
                     sd.getFacilitytype() + "," +
                     sd.getLocation() + "," +
                     sd.getConsumptionAmount() + "\n"); // 包含消费金额
         }
         fw.close();
         System.out.println("充电桩数据已保存到 " + fileName);
     }

     // main方法
     public static void main(String[] args) throws IOException {
         saveLocationsToCSV(generateStations(2000), "data/stations_dataset1.csv");
     }}
